/*
 * CClient.cpp
 *
 *  Created on: 05.03.2012
 *      Author: caffeine
 */

#include "CClient.h"
#include <stdio.h>
 #include <lampe/exception/Null.h>

namespace lampe{
namespace network{

void CClient::onConnected(){
	callback->ready(this);
	callback->onConnected();
}

void CClient::onDisconnected(){
	callback->onDisconnected();
}

void CClient::readData(){
	callback->readData();
}

CClient::CClient(IClientCallback*cb):CThread(){
	callback=cb;
	if (!callback)
		GEN_NULL_ERROR("Client callback can't be NULL");
	callback->grab();
}

void CClient::threadRunning(){
	try{
		readData();
	}catch(...){
		stop();
	}
}

CClient::~CClient(){
	stop();
	callback->drop();
}

}//namespace network
}//namespace lampe
